#!/usr/bin/env python
#coding=utf-8
# author:wade
# contact: 317909531@qq.com
# datetime:2020/4/4 13:45
from rest_framework import serializers
from wangming import models
"""
文件说明：对数据库模型的基本序列化表格，展示所有的1级字段信息
"""

# 类型序列化
class B_WangMing_Type_serializers(serializers.ModelSerializer):
    # ms_grades = serializers.StringRelatedField(many=True)  # 一找多，用_str_字段展示关系
    # ms_grades = serializers.PrimaryKeyRelatedField(many=True,read_only=True)  # 一找多，用关系表的主键展示关系
    # ms_grades = serializers.SlugRelatedField(many=True,read_only=True,slug_field='STATUE') # 一找多，用关系表的内容属性展示关系
    class Meta:

        model = models.WangMing_Type
        fields = '__all__'
        # depth = 3

# 项目序列化
class B_WangMing_Score_serializers(serializers.ModelSerializer):
    def to_representation(self, instance):  #对于空值进行处理，防止给前端的是null
        data = super().to_representation(instance)
        for i in data:
            if not data[i]:
                data[i] = ""

        return data

    class Meta:
        model = models.WangMing_Score
        fields = '__all__'
        # depth = 3

# 符号表序列化
class B_WangMing_CharS_serializers(serializers.ModelSerializer):

    def to_representation(self, instance):  #对于空值进行处理，防止给前端的是null
        data = super().to_representation(instance)
        for i in data:
            if not data[i]:
                data[i] = ""

        return data
    class Meta:
        model = models.WangMing_Chars
        fields = '__all__'
        # depth = 3